import {HOME_ITEM_CONSTRUCT, HOME_ITEM_LIST} from "../constants/home";
import {API_HOME_CONSTRUCT, API_HOME_ITEM_LIST} from "../constants/api";
import api from "../services/api";
/**
 * 首页数据
 * @param {*} payload
 */
export const getOneConstruct = (payload) => {
  return dispatch => {
    api.get(API_HOME_CONSTRUCT, payload).then((res) => {
      // 将数据发送出去
      dispatch({
        type: HOME_ITEM_CONSTRUCT,
        // 将拉取到数据, 发送出去给reducers监听
        payload: {
          data: res || {}
        }
      });
      return res;
    })
  }
};

export const homeItemList = (payload) => {
  return dispatch => {
    api.get(API_HOME_ITEM_LIST, payload).then((res) => {
      // 将数据发送出去
      dispatch({
        type: HOME_ITEM_LIST,
        // 将拉取到数据, 发送出去给reducers监听
        payload: {
          items: res?.items || []
        }
      });
      return res;
    })
  }
};
